package org.lcx.pipeline.example;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.lcx.pipeline.PipelineManager;
import org.lcx.pipeline.bean.PipelineResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:org/lcx/pipeline/example/pipeline-order.xml"})
public class TestSubmitOrderChain {

    @Autowired
    private PipelineManager pipelineManager;

    /**
     * 默认情况下，maven不会打包xml文件，需要运行此方法，参考：https://blog.csdn.net/qq_27840695/article/details/81095601
     */
    @Test
    public void testPipeline() {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            System.out.println("=======> 从数据库，或nacos, 或 redis, 或application.yml 等地方；读取具体路径配置");
			/*
			* ref="startProcessor"/>
			* returnValue="1" link="distanceLink"/>
 	          returnValue="2" link="speedLink"/>
              returnValue="3" link="stockLink"/>
			* */
            // 配置项，入口是哪一个
            params.put("start", 2);
			/*
			* ref="distanceProcessor"/>
              returnValue="1" link="speedLink"/>
              returnValue="2" link="stockLink"/>
			* */
            params.put("distanceNext", 2);
			/*
			 * ref="speedProcessor"/>
               returnValue="1" link="distanceLink"/>
               returnValue="2" link="stockLink"/>
			 */
            params.put("speedNext", 1);
			/*
			 * ref="stockProcessor"/>
               returnValue="1" link="distanceLink"/>
               returnValue="2" link="speedLink"/>
			 */
            params.put("stockNext", 0);

			/*
			STOP_CHAIN_EXECUTION_AND_ROLLBACK = -1;

            STOP_CHAIN_EXECUTION_AND_COMMIT = 0;
			 */


            pipelineManager.runProcess("testSubmitOrderPipelineChain", params);
            System.out.println("查看一下最终结果呢：");
            params.forEach((k,v) -> {
                System.out.println("k:" + k +", v:" + v);
            });
            System.out.println("pipelineChainName运行完毕");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
